package com.wct.permission.controller;

import com.wct.permission.security.MyUserDetails;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author WEI (Email:changtan20000@163.com)
 * @description
 * @date 2020/2/10 13:47
 */
@Controller
@RequestMapping("/product")
public class ProductController {

    /**
     * 商品添加
     */
    @RequestMapping("/index")
    public String index(Model model) {
        // 获取登录用户
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (principal != null) {
            if (principal instanceof UserDetails) {
                MyUserDetails myUserDetails = (MyUserDetails) principal;
                model.addAttribute("username", myUserDetails.getUsername());
                model.addAttribute("realName", myUserDetails.getRealName());
            }
        }
        return "index";
    }

    /**
     * 商品添加
     */
    @RequestMapping("/add")
    public String add() {
        return "product/productAdd";
    }

    /**
     * 商品删除
     */
    @RequestMapping("/delete")
    public String delete() {
        return "product/productDelete";
    }

    /**
     * 商品更新
     */
    @RequestMapping("/update")
    public String update() {
        return "product/productUpdate";
    }

    /**
     * 商品列表
     */
    @RequestMapping("/list")
    public String list() {
        return "product/productList";
    }
}
